const mongoose = require('mongoose')
const { getConf } = require('../config/config')
const log4js = require('../config/log4js')
const log = log4js.getLogger()

mongoose.connect(getConf('db:mongo:uri'), {
  useNewUrlParser: true,
  useUnifiedTopology: true
}).then(res => {
  log.info('mongodb connect success')
}).catch(err => {
  log.error(err)
})

// const path = require('path')
// const fs = require('fs')
// const exports = {}
// const files = fs.readdirSync(__dirname)
// for (let i = 0; i < files.length; i++) {
//   const filename = path.join(__dirname, files[i])
//   const r = require(filename)
//   if (r['name'] && r['schema']) {
//     exports[r['name']] = mongoose.model(r['name'], r['schema'])
//   }
// }

// module.exports = exports

module.exports = {
  Task: require('./model/Task'),
  User: require('./model/User'),
  Book: require('./model/Book'),
  RegCode: require('./model/RegCode'),
  BookShelf: require('./model/BookShelf'),
  UnDownloadedBook: require('./model/UnDownloadedBook')
}
